﻿using System;
using System.Drawing;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media.Imaging;

namespace Vtron.LEDCorrective.Client
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class FullScreenWindow : Window
    {
        public FullScreenWindow(int width, int height, Thickness thickness, Color color, int blockColumn, int blockRow, int blockNum)
        {
            InitializeComponent();

            int column = (blockNum - 1) % blockColumn;
            int row = (blockNum - 1) / blockRow;

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height);
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if ((i - column) % blockColumn == 0 && (j - row) % blockRow == 0)
                    {
                        bmp.SetPixel(i, j, System.Drawing.Color.FromArgb(255, color.R, color.G, color.B));
                    }
                    else
                    {
                        bmp.SetPixel(i, j, System.Drawing.Color.FromArgb(0, 0, 0, 0));
                    }
                }
            }

            var imgsource = Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            image.Source = imgsource;
            image.Margin = thickness;
        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                Close();
            }
        }
    }
}
